package com.xizi.lotterySystem.dao.mapper;

import com.xizi.lotterySystem.dao.dataobject.ActivityUserDO;
import com.xizi.lotterySystem.service.enumerate.ActivityUserStatusEnum;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {
    @Insert("<script> " +
            " insert into activity_user " +
            " (activity_id,user_id,user_name,status)" +
            " values " +
            " <foreach collection='items' item='item' separator=','>" +
            " (#{item.activityId},#{item.userId},#{item.userName},#{item.status})" +
            " </foreach>" +
            " </script>")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int batchInsert(@Param("items") List<ActivityUserDO> activityUserDOList);

    @Select("<script>"
            + " SELECT id"
            + " FROM user"
            + " where"
            + "  id IN"
            + "   <foreach collection='ids' item='id' open='(' separator=',' close=')'>"
            + "     #{id}"
            + "   </foreach>"
            + "</script>")
    List<Long> selectUserIds(@Param("ids") List<Long> userIds);

    @Select("select * from activity_user where activity_id = #{activityId}")
    List<ActivityUserDO> selectByActivityId(Long activityId);

    @Update("<script>" +
            " update activity_user set " +
            " status = #{status}" +
            " where activity_id = #{activityId} and user_id in" +
            " <foreach collection='userIds' item='userId' open='(' separator=',' close=')'>" +
            "    #{userId}" +
            " </foreach>" +
            " </script>")
    Long batchUpdateStatus(@Param("userIds") List<Long> userIds,
                           @Param("activityId")Long activityId,
                           @Param("status") ActivityUserStatusEnum targetActivityUserStatusEnum);
}
